<?php
class Core_db_slave extends Core_db_abstract
{
	public static function getSlave()
	{
		static $db = null;
		
		if($db != null)
		{
			return $db;
		}
		
		$dbSlavesConfig = Core_config::getConfig('DB_SLAVES');
		
		$slaveNum = count($dbSlavesConfig);
		
		if($slaveNum < 1)
		{
			return Core_db_master::getMaster();
		}
		else if($slaveNum == 1)
		{
			return self::_getDbConn($dbSlavesConfig[0]);
		}
		else
		{
			$id = rand(0, $slaveNum - 1);
			$db = self::_getDbConn($dbSlavesConfig[$id]);
			return $db;
		}
	}
}